import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guide_vip";

export const index_api = (showError = true) => {
  return Http.get<{ img_url: string; product_list: any[]; icon_list: any[] }>(
    `/v3${baseUrl}/index`
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const create_order_api = (
  data: { product_id: string },
  showError = true
) => {
  return Http.post<{ order_id: string }>(
    `/v3${baseUrl}/create_order`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
